- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.9k
 
[Android] Fix WebView in a grid expands beyond it's cell #32145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Android] Fix WebView in a grid expands beyond it's cell #32145
Conversation
| 
           Hey there @@devanathan-vaithiyanathan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.  | 
    
| 
           /azp run MAUI-UITests-public  | 
    
| 
          
Azure Pipelines successfully started running 1 pipeline(s). | 
    
| return false; | ||
| 
               | 
          ||
| // Check if URL is about:blank (case insensitive) | ||
| return string.Equals(url.Trim(), "about:blank", StringComparison.OrdinalIgnoreCase); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could expand to more variants?
Examples:
- "about:blank#"
 - "about:blank/"
 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be invoked on every Navigation. The impact on performance now is minimal for the current simple string comparison, but take this into account (for example, if think in use URI parsing or more complex stuff).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz , When the source is null, we set the default WebView source to about:blank. As a result, the OnPageFinished method always receives about:blank as the parameter. Therefore, handling additional variants such as about:blank# or about:blank/ is not necessary in this case.

| 
           /azp run  | 
    
| 
          
Azure Pipelines successfully started running 3 pipeline(s). | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an Android-specific issue where a WebView without a source would expand beyond its Grid cell boundaries. The fix reintroduces the else block that loads about:blank when there's no source, while preventing the Navigated event from firing for this default navigation.
- Restores layout bounds handling by loading 
about:blankwhen WebView has no source - Adds filtering logic to suppress Navigated events for 
about:blanknavigation - Includes UI test to verify WebView stays within Grid cell boundaries
 
Reviewed Changes
Copilot reviewed 4 out of 8 changed files in this pull request and generated 1 comment.
| File | Description | 
|---|---|
| src/Core/src/Platform/Android/WebViewExtensions.cs | Reintroduces else block to load about:blank when WebView has no source | 
| src/Core/src/Platform/Android/MauiWebViewClient.cs | Adds IsBlankNavigation helper and filters Navigated event for blank URLs | 
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32030.cs | Adds NUnit test to verify WebView layout behavior | 
| src/Controls/tests/TestCases.HostApp/Issues/Issue32030.cs | Adds test page demonstrating WebView in Grid without source | 
Comments suppressed due to low confidence (1)
src/Controls/tests/TestCases.HostApp/Issues/Issue32030.cs:1
- Corrected spelling of 'it's' to 'its' in the issue description. 'Its' is the possessive form, while 'it's' means 'it is'.
 
namespace Maui.Controls.Sample.Issues;
| if (string.IsNullOrWhiteSpace(url)) | ||
| return false; | 
    
      
    
      Copilot
AI
    
    
    
      Oct 28, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check IsNullOrWhiteSpace returns false for blank URLs, but the method is named IsBlankNavigation. This is counterintuitive - a null or whitespace URL could reasonably be considered 'blank'. Consider returning true for null/whitespace URLs, or rename the method to clarify its purpose (e.g., IsAboutBlankUrl).
| if (string.IsNullOrWhiteSpace(url)) | |
| return false; | |
| // Return true for null, empty, or whitespace URLs | |
| if (string.IsNullOrWhiteSpace(url)) | |
| return true; | 
| 
               | 
          ||
| static bool IsBlankNavigation(string? url) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(url)) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (navigate && !IsBlankNavigation(url))
Based on this:
- url = null → IsBlankNavigation returns false → Navigated fires
 - url = "about:blank" → IsBlankNavigation returns true → Navigated doesn't fire
 
This could break the fix from #29234 which wanted to prevent events when Source is null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz ,
url = null → IsBlankNavigation returns false → Navigated fires
url should never be null. We’ve modified the source so that if the source is not null, it uses that source; otherwise, it uses "about:blank".
In the OnPageFinished method, url should never be null.
url = "about:blank" → IsBlankNavigation returns true → Navigated doesn’t fire
Yes, this is the expected behavior. The PR#29234 resolves the issue where Android triggered the Navigating event with a null source.
With my fix, if the source is null, we set it to "about:blank". When the URL is "about:blank", the Navigating event will not fire.
So with the current fix, it resolves both issues #32030 and #29234.
| 
           /rebase  | 
    
4ec3cf9    to
    c544158      
    Compare
  
    | 
           /azp run  | 
    
| 
          
Azure Pipelines successfully started running 3 pipeline(s). | 
    
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
After PR #29234 , the else part was removed to stop the Navigated event from triggering when the WebView had no source.
However, this caused a new issue where rendering a WebView without a source exceeded the layout bounds.
Root Cause
When the WebView was rendered without a source, the layout logic was not properly handled — causing the WebView to exceed its layout bounds.
Description of Change
This fix resolves both the layout overflow and unwanted event trigger issues.
Issues Fixed
Fixes #32030
Tested the behavior in the following platforms.